<?php
namespace app\user\model\user;

use app\common\model\BaseModel;
use app\school\model\school\School;
use think\model\concern\SoftDelete;

/**
 * 购物车模型
 */
class Cart extends BaseModel
{
    use SoftDelete;
    /**
     * 表名
     * @var string
     */
    protected $name = 'course_cart';
    /**
     * 隐藏课时数据
     * @var [type]
     */
    protected $hidden = ['update_time','delete_time'];

    /**
     * 定义字段类型
     * @var array
     */
    protected $type = [
        'id'          => 'integer',
        'user_id'     => 'integer',
        'course_id'   => 'integer',
        'create_time' => 'integer',
        'update_time' => 'integer'
    ];

/* 查询范围 */

    public function scopeFetch($query)
    {
        $query->where('user_id', request()->mid)->order('create_time', 'DESC');
    }

/* 关联 */

    public function course()
    {
        return $this->belongsTo(Course::class,'course_id');
    }

    /**
     * 课程
     * Author   亓官雨树<lucky.max@foxmail.com>
     * Date 2020-04-27
     * @return   [type]                      [description]
     */
    public function schoolName()
    {
        return $this->belongsTo(School::class, 'mhm_id')->bind(['school_name' => 'title']);
    }

}

